/// @description Insert description here
// You can write your code in this editor

if(!frozen){
	//exit;

if((keyboard_check_direct(global.upKey) == true || keyboard_check_direct(global.downKey) == true) && ladder == false && place_meeting(image_xscale==1 ? x:x+32,y,objLatter) == true){
      ladder = true;
      tjump=true;
}
if(ladder == true){
      if(place_meeting(image_xscale==1 ? x:x+32,y,objLatter) == false){
        ladder = false;
      }else{
		var temi = collision_line(x+1,y+32,x+31,y+32,objBlockFather,0,0)
		var temii = collision_line(x+1,y+13-speed-1,x+31,y+13-speed-1,objBlockFather,0,0)
		var temiii = collision_line(x+1,y+13-speed-1,x+31,y+13-speed-1,objLatter,0,0)
        if(keyboard_check_direct(global.upKey) == true){
          if(!temii && temiii) y -= 4;
          gravity = 0;
          vspeed = 0;
          //ladderud = 1;
        }
        if(keyboard_check_direct(global.downKey) == true){
          if(!temi) y += 4;
          gravity = 0;
          vspeed = 0;
          //ladderud = 1;
        }
       if(keyboard_check_direct(global.cancelKey) == true){
          //ladderjump=true
          ladder=false;
    }
  }
}


var dx=0,psp=4;

if(dx==0 && keyboard_check_direct(global.leftKey)){
	dx=-1;
	image_index+=0.1;
}
if(dx==0 && keyboard_check_direct(global.rightKey)){
	dx=1;
	image_index+=0.1;
}
face = dx==0 ? face : (dx==1 ? 6:4)
var tem1 = collision_line(x+15+dx*16,y,x+15+dx*16,y+31,objBlockFather,0,0),tem2 = collision_line(x+17+dx*16,y,x+17+dx*16,y+31,objBlockFather,0,0)
//var collsion = place_meeting(x+dx*psp,y,objBlockFather) && place_free(x+dx*psp,y) == false;
//if(collsion == false){
//	x += dx*psp;
//}
if(!tem1 and dx<=0){
	x += dx*psp
	//image_index+=0.1;
}
if(!tem2 and dx>=0){
	x += dx*psp
}
}
if(jump = false && tjump = true && keyboard_check_pressed(global.cancelKey)){
	tjump = false;
	speed = 6;
	direction = 90;
	gravity = 0.3;
}

if(jump == true && ladder == false){
	var tem = collision_line(x+1,y+32,x+31,y+32,objBlockFather,0,0)
	if(!tem){
		jump = false
		speed = 1.5;
		direction = 270;
		gravity = 0.3;
	}else if(keyboard_check_pressed(global.cancelKey) && !frozen){
		jump = false;
		speed = 7;
		direction = 90;
		gravity = 0.3;
	}
}
if(jump = false and direction == 270){
	var tem = collision_line(x+1,y+32+speed,x+31,y+32+speed,objBlockFather,0,0)
	if(tem){
		jump = true
		tjump = true;
		speed = 0
		direction = 270
		gravity = 0
		//show_debug_message()
		//(object_get_name(tem)
		if(tem.object_index == objDuck){
			//show_debug_message(1);
			y = tem.y + 21 - sprite_height;
			//hspeed = tem.hspeed;
			//if(face == 6 ? !collision_line(x+1,y,x+1,y+30,objBlockFather,0,0):!collision_line(x+31,y,x+31,y+30,objBlockFather,0,0)){
			//	x = x+tem.hspeed;
			//}else{
				//hspeed=-hspeed;
			//}
		}else{
			y = tem.y - tem.sprite_height;
		}
	}
}
if(jump = false and direction == 90){
	var tem = collision_line(x+1,y+13-speed-1,x+31,y+13-speed-1,objBlockFather,0,0)
	if(tem){
		jump = true;
		var tem2 = collision_line(x+1,y+32+speed,x+31,y+32+speed,objBlockFather,0,0);
		if(tem2) tjump = true;
		speed = 0
		direction = 90
		gravity = 0
		y = tem.y + tem.sprite_height
		//y = tem.y + tem.sprite_height
	}
}
if(!frozen){
if(jump == true && ladder == false && keyboard_check_pressed(global.skillKey[| 0]) && time[0]==0 && global.dskill){
	frozen = true;
	alarm[0] = 60;
}//https://www.yzhhsdreamisland.cn/index.php/bowsehax/

if(jump == true && ladder == false && keyboard_check_pressed(global.skillKey[| 1]) && time[1]==0 && global.dskill){
	frozen = true;
	alarm[1] = 60;
}

if(jump == true && ladder == false && keyboard_check_pressed(global.skillKey[| 2]) && time[2]==0 && global.dskill){
	frozen = true;
	alarm[2] = 60;
}
}